package team2.game.crow;

import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.util.pool.GenericPool;

/**
 * Class for holding a pool of hit sparks
 * 
 * @author Isaiah
 * Last update 9/29/2011
 */
public class AnimatedSpritePool extends GenericPool<HitSpark> {

	// ===========================================================
	// Constants
	// ===========================================================

	// ===========================================================
	// Fields
	// ===========================================================
	
	private TiledTextureRegion animSprite;

	// ===========================================================
	// Constructors
	// ===========================================================
	
	AnimatedSpritePool(TiledTextureRegion animSprite){
		this.animSprite = animSprite;
		this.batchAllocatePoolItems(40);
	}
	
	// ===========================================================
	// Getter & Setter
	// ===========================================================
	
	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================
	
	//Called When a new sprite is needed 
	@Override
	protected HitSpark onAllocatePoolItem() {
		return new HitSpark(800, 800, animSprite.deepCopy());
	}
	
	//Called when a sprite is sent to the pool
	@Override
	protected void onHandleRecycleItem(final HitSpark animSprite){
        animSprite.setPosition(800, 800);
        animSprite.setMode(0);
        animSprite.setAngle(0);
        animSprite.deactivate();
        animSprite.stopAnimation();
	}
	
	//Called just before it is sent to the caller
	@Override
	protected void onHandleObtainItem(final HitSpark animSprite) {
		animSprite.expired = false;
		animSprite.time = 0;
		animSprite.activate();
	}

	// ===========================================================
	// Methods
	// ===========================================================

	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================
}

